//
//  APIBatchRequestManger.h
//  YYYNetWorkDemo
//
//  Created by yyy on 2016/12/8.
//  Copyright © 2016年 yyy. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class APIBatchRequestManger;
@class APIBaseManager;

@protocol APIBatchRequestDelegate <NSObject>

@optional
- (void)batchRequestSuccess:(APIBatchRequestManger *)batchRequest;
- (void)batchRequestFailed:(APIBatchRequestManger *)batchRequest;
- (void)batchRequestDidComplete:(APIBatchRequestManger *)batchRequest success:(BOOL)success;

//当有一个Manager 的请求失败的时候就会走这个方法，如果return NO，则整个请求停止，如果 return YES 则忽略该失败，继续请求。
- (BOOL)batchRequest:(APIBatchRequestManger *)batchRequest didFailedWithManager:(APIBaseManager *)manager;

@end

/**
 批量请求
 */
@interface APIBatchRequestManger : NSObject

@property (nonatomic, strong, readonly) NSArray<APIBaseManager *> *requestArray;
@property (nonatomic, weak, nullable) id <APIBatchRequestDelegate> delegate;
@property (nonatomic, copy, nullable) void (^completionBlock)(BOOL success, APIBatchRequestManger *batchManager);
@property (nonatomic, strong, readonly, nullable) APIBaseManager *failedRequest;

- (instancetype)initWithRequestArray:(NSArray<APIBaseManager *> *)requestArray;
- (void)start;
- (void)stop;
- (void)startWithCompletionBlock:(nullable void (^)(BOOL success, APIBatchRequestManger *batchManager))complete;

@end

NS_ASSUME_NONNULL_END
